bitkeeper revision 1.1550.1.2 (4294a1f1_I9jQ97QY8OTqDCx1kDIUA)
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Wed, 25 May 2005 16:04:01 +0000 (16:04 +0000)
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Wed, 25 May 2005 16:04:01 +0000 (16:04 +0000)
SrvDaemon.py, XendRoot.py, relocate.py:
  Add relocation server.
XendCheckpoint.py:
  Import XendError.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
.rootkeys
tools/python/xen/xend/XendCheckpoint.py
tools/python/xen/xend/XendRoot.py
tools/python/xen/xend/server/SrvDaemon.py
tools/python/xen/xend/server/relocate.py [new file with mode: 0644]

index adfd52f59754bd846a9cc6942071b3deb9b0f160..0e2535c7f5a5064d72239635781df7a1a78340c1 100644 (file)
--- a/.rootkeys
+++ b/.rootkeys
 40c9c46925x-Rjb0Cv2f1-l2jZrPYg tools/python/xen/xend/server/netif.py
 40c9c469ZqILEQ8x6yWy0_51jopiCg tools/python/xen/xend/server/params.py
 4266169eI_oX3YBjwaeC0V-THBRnjg tools/python/xen/xend/server/pciif.py
+4294a1bf8rMUcddot-B2-pOxORimOg tools/python/xen/xend/server/relocate.py
 41ee5e8dq9NtihbL4nWKjuSLOhXPUg tools/python/xen/xend/server/usbif.py
 40c9c469LNxLVizOUpOjEaTKKCm8Aw tools/python/xen/xend/sxp.py
 40d05079aFRp6NQdo5wIh5Ly31c0cg tools/python/xen/xm/__init__.py
index 66887efc2a54347f3681f1e8c06c274e9df22a49..e3908df885fa2f092fe764c819bfaece1e0c71cc 100644 (file)
@@ -13,6 +13,7 @@ from struct import pack, unpack, calcsize
 from xen.util.xpopen import xPopen3
 import xen.lowlevel.xc; xc = xen.lowlevel.xc.new()
 
+from XendError import XendError
 from XendLogging import log
 
 SIGNATURE = "LinuxGuestRecord"
index 74f736616cff70b527e40bcc8d5bfb0b478e2889..cae7c7608c3d4c1940214464e742e02188961c72 100644 (file)
@@ -51,12 +51,21 @@ class XendRoot:
     """Default interface address xend listens at. """
     xend_address_default      = ''
 
+    """Default for the flag indicating whether xend should run a relocation server."""
+    xend_relocation_server_default = 'yes'
+
+    """Default interface address the xend relocation server listens at. """
+    xend_relocation_address_default = ''
+
     """Default port xend serves HTTP at. """
     xend_port_default         = '8000'
 
     """Default port xend serves events at. """
     xend_event_port_default   = '8001'
 
+    """Default port xend serves relocation at. """
+    xend_relocation_port_default = '8002'
+
     """Default for the flag indicating whether xend should run a unix-domain server."""
     xend_unix_server_default = 'yes'
 
@@ -249,6 +258,11 @@ class XendRoot:
         """
         return self.get_config_bool("xend-http-server", self.xend_http_server_default)
 
+    def get_xend_relocation_server(self):
+        """Get the flag indicating whether xend should run a relocation server.
+        """
+        return self.get_config_bool("xend-relocation-server", self.xend_relocation_server_default)
+
     def get_xend_port(self):
         """Get the port xend listens at for its HTTP interface.
         """
@@ -259,6 +273,11 @@ class XendRoot:
         """
         return self.get_config_int('xend-event-port', self.xend_event_port_default)
 
+    def get_xend_relocation_port(self):
+        """Get the port xend listens at for connection to its relocation server.
+        """
+        return self.get_config_int('xend-relocation-port', self.xend_relocation_port_default)
+
     def get_xend_address(self):
         """Get the address xend listens at for its HTTP and event ports.
         This defaults to the empty string which allows all hosts to connect.
@@ -267,6 +286,14 @@ class XendRoot:
         """
         return self.get_config_value('xend-address', self.xend_address_default)
 
+    def get_xend_relocation_address(self):
+        """Get the address xend listens at for its HTTP and event ports.
+        This defaults to the empty string which allows all hosts to connect.
+        If this is set to 'localhost' only the localhost will be able to connect
+        to the HTTP and event ports.
+        """
+        return self.get_config_value('xend-relocation-address', self.xend_relocation_address_default)
+
     def get_xend_unix_server(self):
         """Get the flag indicating whether xend should run a unix-domain server.
         """
index 85c1c23560844e533738b1305c33b36795beab3b..6e297b92fa2e7bbab476b7819bbbc5bb190fc3be 100644 (file)
@@ -30,6 +30,7 @@ from xen.xend.XendLogging import log
 import channel
 import controller
 import event
+import relocate
 from params import *
 
 DAEMONIZE = 0
@@ -302,6 +303,7 @@ class Daemon:
             log.info("Xend Daemon started")
             self.createFactories()
             event.listenEvent(self)
+            relocate.listenRelocation()
             self.listenChannels()
             servers = SrvServer.create()
             self.daemonize()
diff --git a/tools/python/xen/xend/server/relocate.py b/tools/python/xen/xend/server/relocate.py
new file mode 100644 (file)
index 0000000..f41872c
--- /dev/null
@@ -0,0 +1,125 @@
+import sys
+import StringIO
+
+from xen.web import reactor, protocol
+
+from xen.xend import scheduler
+from xen.xend import sxp
+from xen.xend import EventServer; eserver = EventServer.instance()
+from xen.xend.XendError import XendError
+from xen.xend import XendRoot; xroot = XendRoot.instance()
+from xen.xend.XendLogging import log
+from xen.xend import XendCheckpoint
+
+DEBUG = 0
+
+class RelocationProtocol(protocol.Protocol):
+    """Asynchronous handler for a connected relocation socket.
+    """
+
+    def __init__(self):
+        #protocol.Protocol.__init__(self)
+        self.parser = sxp.Parser()
+
+    def dataReceived(self, data):
+        try:
+            self.parser.input(data)
+            if self.parser.ready():
+                val = self.parser.get_val()
+                res = self.dispatch(val)
+                self.send_result(res)
+            if self.parser.at_eof():
+                self.loseConnection()
+        except SystemExit:
+            raise
+        except:
+            self.send_error()
+
+    def loseConnection(self):
+        if self.transport:
+            self.transport.loseConnection()
+        if self.connected:
+            scheduler.now(self.connectionLost)
+
+    def connectionLost(self, reason=None):
+        pass
+
+    def send_reply(self, sxpr):
+        io = StringIO.StringIO()
+        sxp.show(sxpr, out=io)
+        print >> io
+        io.seek(0)
+        if self.transport:
+            return self.transport.write(io.getvalue())
+        else:
+            return 0
+
+    def send_result(self, res):
+        if res is None:
+            resp = ['ok']
+        else:
+            resp = ['ok', res]
+        return self.send_reply(resp)
+
+    def send_error(self):
+        (extype, exval) = sys.exc_info()[:2]
+        return self.send_reply(['err',
+                                ['type', str(extype)],
+                                ['value', str(exval)]])
+
+    def opname(self, name):
+         return 'op_' + name.replace('.', '_')
+
+    def operror(self, name, req):
+        raise XendError('Invalid operation: ' +name)
+
+    def dispatch(self, req):
+        op_name = sxp.name(req)
+        op_method_name = self.opname(op_name)
+        op_method = getattr(self, op_method_name, self.operror)
+        return op_method(op_name, req)
+
+    def op_help(self, name, req):
+        def nameop(x):
+            if x.startswith('op_'):
+                return x[3:].replace('_', '.')
+            else:
+                return x
+        
+        l = [ nameop(k) for k in dir(self) if k.startswith('op_') ]
+        return l
+
+    def op_quit(self, name, req):
+        self.loseConnection()
+
+    def op_receive(self, name, req):
+        if self.transport:
+            self.send_reply(["ready", name])
+            self.transport.sock.setblocking(1)
+            xd = xroot.get_component("xen.xend.XendDomain")
+            XendCheckpoint.restore(xd, self.transport.sock.fileno())
+            self.transport.sock.setblocking(0)
+        else:
+            log.error(name + ": no transport")
+            raise XendError(name + ": no transport")
+
+class RelocationFactory(protocol.ServerFactory):
+    """Asynchronous handler for the relocation server socket.
+    """
+
+    def __init__(self):
+        #protocol.ServerFactory.__init__(self)
+        pass
+
+    def buildProtocol(self, addr):
+        return RelocationProtocol()
+
+def listenRelocation():
+    factory = RelocationFactory()
+    if xroot.get_xend_unix_server():
+        path = '/var/lib/xend/relocation-socket'
+        reactor.listenUNIX(path, factory)
+    if xroot.get_xend_relocation_server():
+        port = xroot.get_xend_relocation_port()
+        interface = xroot.get_xend_relocation_address()
+        reactor.listenTCP(port, factory, interface=interface)